<?php 
$active = 'account';
$edit = 'photos';
require("../db/opendb.php");
include("common/functions.php");

$query = "select * from Users where Username='".$_GET["username"]."' and Password='".$_GET["password"]."'";
$result = mysql_query($query) or die ("SQL Error".mysql_error());
if(!mysql_num_rows($result))
{
	echo "invalid Realivent User";
	exit();
} 
else
{
$urow=mysql_fetch_assoc($result);

$ListingID = $_GET['listing_id'];
if(isset($_POST['area_submit']) && $_POST['area'] != "")
{
	$query = "Insert into Biz_Listing_Areas(Owner, Listing_ID, Name, Date_Created)Values('".$urow['ID']."','".$ListingID."','".$_POST['area']."','".date('Y-m-d H:i:s')."')";
	//echo $query;
	mysql_query($query) or die(mysql_error()); 
}

?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html><head>
<title>Add Photos Listing</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<style href='../style.css' type="text/css"></style>
<script type="text/javascript" src="frame_ajax.js"></script>
<script type="text/javascript">
function edit_area_description(id)
{
	var text
	text = document.getElementById("area_result"+id).innerHTML
	document.getElementById("area_desc_edit"+id).innerHTML="<div style='font-size:12px;'><strong>Description:</strong><Br><textarea id='text_area"+id+"' name='text_box_area' style='width:90%' rows='2'>"+text+"</textarea><BR><input onClick=Update_Area_Description("+id+") name='update_area_desc' type='button' value='Update'>"
}

function edit_photo_description(id)
{
	var text
	text = document.getElementById("pic_result"+id).innerHTML
	document.getElementById("picture"+id).innerHTML="<div style='font-size:12px;'><strong>Description:</strong><Br><textarea id='pic_text"+id+"' name='text_box_area' style='width:90%' rows='2'>"+text+"</textarea><BR><input onClick=Update_Picture_Description("+id+") name='update_area_desc' type='button' value='Update'>"
}
function main_photo(formid)
{
	var id = formid
	//alert(id)
	document.getElementById(id).submit();
}
</script>
<link rel="stylesheet" type="text/css" href="style.css">
<link rel="stylesheet" type="text/css" href="listing_panel_css.css">
</head>

<body>
<CENTER>
<table width="800" border="0" cellspacing="0" cellpadding="0">
<TR><TD>	
<div id="invertedtabsline">&nbsp;</div>
<div style="font-size:20px; color:#CCCCCC">Step 1. Add Business Details >><span style="color:#000099"> Step 2. Add Photos & Logos >> </span>Step 3. Publish</div><BR><BR>
</TD></TR>
<TR><TD>
	<table width="100%"  border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width="0" valign="top" align="left">
	
	</td>
    <td width="800" valign="top" align="left" id=main_body>

			<!--<div style="float:left" id=property_title>
				<?php 
				//if($ListingID != 0){include('frame_change_listing_include.php');}
				 ?>
				</div>
			<div id="invertedtabsline">&nbsp;</div>
			 <?php //include('frame_listing_menu_control.php'); ?>
				<BR><BR>-->

		 <?php $query = "select p.* from BIZPROPERTIES p inner join Biz_Owner_Con c on p.OID = c.Prop_OID where OID = '".$ListingID."' and c.Owner = '".$urow['ID']."'";
			$result = mysql_query($query) or die ("SQL Error".mysql_error());
			$row=mysql_fetch_assoc($result);
			{	
				if (mysql_num_rows($result) === 0)
				{
				
				echo "Please make sure that you have entered the required data for this listing and you have the permission to edit this listing.";
				}
				else
				{
				echo "Please add various areas of the house (Kitchen, Bedrooms, Bathrooms and more).  Creating these Areas helps better organization of photos.  Once you have created the Area placeholders, you can upload multiple photos for each of these areas.";

			?>
			<BR><BR>

		
			<!--This addes the areas for the house -->
				<form style="background-color:#FFFFCC" action="frame_edit_photos_biz_listings.php?source=<?php echo $_GET['source'] ?>&username=<?php echo $_GET['username'] ?>&password=<?php echo $_GET['password'] ?>&listing_id=<?php echo $ListingID; ?>" method="post" name="Form1">
				  <span class="style18">Add new Area:</span> 
				  <input name="area" type="text">
				  <input name="area_submit" type="submit" value="Add Area"> <a href=# onClick="window.open('picture_help.html','picture_help','Location=no, width=500, height=500')">[Click here for help with pictures]</a>
				</form>
				<BR>
				<form target="_parent" action="http://<?php echo $_GET['source'] ?>/map_the_biz.php?digsite=<?php echo $_GET['digsite'] ?>&username=<?php echo $_GET['username'] ?>&password=<?php echo $_GET['password'] ?>&listing_id=<?php echo $ListingID; ?>" method="post" name="Form3">
				  <input name="listing" type="hidden" value="<?php echo $ListingID ?>">
				  <input name="username" type="hidden" value="<?php echo $_GET["username"] ?>">
				  <input name="photo_done" type="submit" value="Next Step"> 
				</form>
				<BR><BR>

	 		<TABLE width="90%">
	 		<?php $query = "select * from Biz_Listing_Areas where Listing_ID = '".$ListingID."' and Type = 'IMAGE' group by Name";
			$result = mysql_query($query) or die ("SQL Error".mysql_error());
			while($row=mysql_fetch_assoc($result))
			{			
			?>
			<TR>
				<TD>
					<table width="90%" border="0" cellspacing="0" cellpadding="0">
					  <tr>
						<td align="center" bgcolor="#FAFFE8" style="border-top:1px solid black;border-left:1px solid black;border-right:1px solid black;" width=200><div style="font-size:18px;"><?php echo $row['Name'] ?></div></td>
						<td width=500 style="border-bottom:1px solid black;" align="right"><a style="font-size:10px; text-decoration:none;" href=frame_delete_biz_area.php?username=<?php echo $_GET['username'] ?>&password=<?php echo $_GET['password'] ?>&area=<?php echo $row['ID'] ?>&listing_id=<?php echo $ListingID; ?>>[Delete Area]</a></td>
					  </tr>
					  <tr>
						<td height="30px" style="border-left:1px solid black;border-right:1px solid black;padding-left: 10px;" colspan="2" bgcolor="#FAFFE8"><div style="font-size:10px;" id=area_desc_edit<?php echo $row['ID']; ?>>
						<div style="font-size:12px;"><strong>Description:</strong>
						<input onClick="edit_area_description(<?php echo $row['ID']; ?>)" style=" font-size:10px;" name="edit_area_description" type="button" value="Edit">
						<BR>
						</div>
						<div id=area_result<?php echo $row['ID']; ?>><?php echo $row['Description']; ?></div>
						</div></td>
						
					  </tr>
					  <tr>
						
						<TD align="right" height="30px;" colspan="2" style="border-right:1px solid black;border-left:1px solid black; font-size:12px;" valign="middle">
						<form name="iform" action="frame_add_photo_biz_listing.php?source=<?php echo $_GET['source'] ?>&username=<?php echo $_GET['username'] ?>&password=<?php echo $_GET['password'] ?>&listing_id=<?php echo $ListingID; ?>" method="post" enctype="multipart/form-data">
						<strong>New Photo:</strong> <input id="file" type="file" name="image" />
						<input name="area_id" type="hidden" value=<?php echo $row['ID'] ?>>
						<input name="add" type="submit" value="Add Photo"></form></TD>
					</tr>
					<TR>
						<TD colspan="2" style="border-left:1px solid black;border-right:1px solid black;border-bottom:1px solid black;">
						<table width="90%" border="0" cellspacing="0" cellpadding="3">
					 <?php 
					 	$lquery = "select * from Biz_Listing_Images where Listing_ID = '".$ListingID."' and Type='IMAGE' and Area = '".$row['ID']."'";
						$lresult = mysql_query($lquery) or die ("SQL Error".mysql_error());
						if(mysql_num_rows($lresult) == 0)
						{
							echo "You have not added any pictures for this area";
						}
						else
						{
						while($lrow=mysql_fetch_assoc($lresult))
						{		
						list($width_orig, $height_orig, $image_type) = getimagesize('../biz_listing_images/resize_'.$lrow['Path']);

						?>
						<TR>
							<TD width=100 align="center"><form id=mainform<?php echo $lrow['ID'] ?> method='post' action='frame_update_main_biz_photo.php?source=<?php echo $_GET['source'] ?>&username=<?php echo $_GET['username'] ?>&password=<?php echo $_GET['password'] ?>'>
							Main Photo
							<?php 
							if($lrow['Main_Photo'] === '1')
							{
							?>
							<input onClick="main_photo('mainform<?php echo $lrow['ID'] ?>')" checked="checked" type="radio" value=<?php echo $lrow['ID'] ?> name="mainid" />
							<?
							}
							else
							{
							?>
							<input onClick="main_photo('mainform<?php echo $lrow['ID'] ?>')" type="radio" value=<?php echo $lrow['ID'] ?> name="mainid" />
							<?
							}
							?>
							
							<input name="listing_ID" type="hidden" value="<?php echo $ListingID; ?>">
							<a href=# onClick="window.open('../biz_listing_images/<?php echo "resize_".$lrow["Path"] ?>','name','location=no,height=<?php echo $height_orig+20; ?>,width=<?php echo $width_orig+20; ?>');"><img align="absmiddle" style="border:1px solid black; " src=../biz_listing_images/t_<?php echo $lrow["Path"]; ?>></a>
							<div><a style="font-size:10px;" href=frame_delete_biz_picture.php??source=<?php echo $_GET['source'] ?>&username=<?php echo $_GET['username'] ?>&password=<?php echo $_GET['password'] ?>&pic_id=<?php echo $lrow['ID']; ?>&listing_id=<?php echo $ListingID; ?>>[delete]</a></div></form></TD>
							<TD style="font-size:12px;" valign="top">
							<div id=picture<?php echo $lrow['ID']; ?>>
							<?php 
							if ($lrow['Description'] == "")
							{
							?>
							 Picture Description (Optional, but you should)<BR>
							<textarea id="pic_text<?php echo $lrow['ID']; ?>" name="desc" style="width:90%;" rows="2"></textarea><br>
							<input onClick="Update_Picture_Description('<?php echo $lrow['ID']; ?>')" style="font-size:10px;" name="add_desc" type="button" value="Update Description">
							<?php 
							}
							else
							{
							echo "<strong>Description:</strong><input onClick=edit_photo_description('".$lrow['ID']."') style='font-size:10px;' name='pic_edit' type='button' value='Edit'><BR><div id=pic_result".$lrow['ID'].">".$lrow['Description']."</div>";
							}
							?>
							
							<!--<form>Add voice:<img align="top" src=../images/new.gif>&nbsp;&nbsp;<input value="coming soon" disabled="disabled" name="voice" type="file">
							<a href=# onClick="window.open('voice_help.php', 'voice_help', 'location=no, height=400, width=300')">More Info</a>
							</form>-->
							</div>
						  </TD>
						</TR>
						
						<?
						}
						}	
						?>
					  <tr>
						<td>
						
						</td>
					  </tr>
					</table>
						</TD>
					</TR>
					</table>
				</td>
  			</tr>
			<?php }?>
		</table>
	</td>
  </tr>
</table>
		
	</td>
  </tr>
	<?
			}	
			}
			?>
</table>
<?php //include('../footer.php'); ?>
</body>
</html>
<?php require("../db/closedb.php");
}
?>